package cn.pupil.springframework.aop.aspectj;

import cn.pupil.springframework.aop.Pointcut;
import cn.pupil.springframework.aop.PointcutAdvisor;
import org.aopalliance.aop.Advice;

/**
 * @Description: AspectJ切入表达式的通知器
 * @Author: pupil
 * @Date: 2024/11/21 下午 4:33
 */
public class AspectJExpressionPointcutAdvisor implements PointcutAdvisor {

    // 切面
    private AspectJExpressionPointcut pointcut;
    // 具体的拦截方法(拦截器)
    private Advice advice;
    // 表达式
    private String expression;

    /**
     * 设置表达式
     *
     * @param expression
     */
    public void setExpression(String expression) {
        this.expression = expression;
    }

    @Override
    public Pointcut getPointcut() {
        if (null == pointcut) {
            pointcut = new AspectJExpressionPointcut(expression);
        }
        return pointcut;
    }


    @Override
    public Advice getAdvice() {
        return advice;
    }

    /**
     * 设置具体的拦截方法
     *
     * @param advice
     */
    public void setAdvice(Advice advice) {
        this.advice = advice;
    }
}
